// pages/address/address.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "",
    phone: "",
    save: "",
    slit: "",
    lists:[],
    id:10
  },

  getname(e){
    this.setData({
      name:e.detail.value
    })
  },
  getphone(e){
    this.setData({
      phone:e.detail.value
    })
  },
  getsave(e){
    this.setData({
      save:e.detail.value
    })
  },
  getslit(e){
    this.setData({
      slit:e.detail.value
    })
  },

  getBtn(){
    let name = this.data.name
    let phone = this.data.phone
    let save = this.data.save
    let slit = this.data.slit
    let id = this.data.id
    let ids = id +=1

    let localist = wx.getStorageSync('editLoca')
    let localists = wx.getStorageSync('addresslists')
    if(localist){
      localists = localists.filter(item=>{
        return item.id != localist.id
      })
      let localis = {
        name,
        phone,
        save,
        slit,
        checked:true,
        id:ids
      }
      localists.push(localis)
      wx.setStorageSync('addresslists',localists);
      wx.setStorageSync('editLoca',"");
      wx.navigateTo({
        url: "/pages/location/location",
      })
    }else{
      let list = {
        name,
        phone,
        save,
        slit,
        checked:true,
        id,
      }
      wx.setStorageSync('address',list);
      wx.navigateTo({
        url: "/pages/location/location",
      })
    }
    
    
    this.setData({
      name:'',
      phone:'',
      save:'',
      slit:'',
      id:ids
    })

   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let list = wx.getStorageSync('editLoca')
    this.setData({
      name:list.name,
      phone:list.phone,
      save:list.save,
      slit:list.slit
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})